const appInfos = require('./app-build-info');
const fs = require('fs');
const path = require('path');


if (appInfos.length < 1) return;
const projectFolder = './app';
const appInfo = appInfos[appInfos.length - 1];
const appPath = path.join(__dirname, projectFolder + '/' + appInfo);

if (fs.existsSync(appPath)) {
    console.log('Creation failed, the project already exists!');
    return;
}

console.log('Start creating project:', appPath);
fs.mkdirSync(appPath);
fs.mkdirSync(appPath + '/asset');
fs.mkdirSync(appPath + '/asset/model');
fs.mkdirSync(appPath + '/asset/texture');
fs.mkdirSync(appPath + '/asset/audio');
fs.mkdirSync(appPath + '/dist');
fs.mkdirSync(appPath + '/src');
fs.mkdirSync(appPath + '/src/ui');
fs.mkdirSync(appPath + '/src/stage');
fs.mkdirSync(appPath + '/src/data');

fs.copyFileSync(path.join(__dirname, "template/favicon.ico"), appPath + '/src/favicon.ico');
fs.copyFileSync(path.join(__dirname, "template/app-config.json"), appPath + '/src/app-config.json');
let entry = fs.readFileSync(path.join(__dirname, "template/app-container.ts.template"), { encoding: "utf8" });
fs.writeFileSync(appPath + '/src/app-container.ts', entry, { encoding: 'utf8', flag: 'w' });
console.log('Project has been successfully created.');